/**
 * Encapsulates a single keyword-value pair.
 *
 * @author Andrew Krieger
 * @version 1.0
 * @since 5 Apr 2012
 */

public class Operand {
    /**
     * An operand keyword
     */
    public static enum Keyword {
	DM, DR, DX, EX, FC, FL, FM, FR, FS, FX, LR, NW, ST;
    }

    /**
     * Initialize a string-valued operand.
     *
     * This should only be used with EX, DR, FR, LR, or ST Keywords
     *
     * @param kw The keyword
     * @param str The string value
     */
    public Operand(Keyword kw, String str) {
	this.kw = kw;
	this.str = str;
	this.num = null;
    }

    /**
     * Initialize an number-valued operand.
     *
     * This should only be used with DM, DX, FC, FL, FM, FS, FX or NW keywords
     *
     * @param kw The keyword
     * @param num the numeric value
     */
    public Operand(Keyword kw, Integer num) {
	this.kw = kw;
	this.str = null;
	this.num = num;
    }

    /**
     * Get the keyword of this operand.
     *
     * @return The keyword
     */
    public Keyword getKeyword() {
	return kw;
    }

    /**
     * Get the string value of this operand.
     *
     * @return The string value
     * @throws NullPointerException if the operand has a numeric-value instead
     */
    public String getString() {
	if(str == null) {
	    throw new NullPointerException(kw + " doesn't have a string value");
	}
	return str;
    }

    /**
     * Get the numeric value of this operand.
     *
     * @return The numeric value
     * @throws NullPointerException if the operand has a string value instead
     */

    public Integer getNumber() {
	if(num == null) {
	    throw new NullPointerException(kw + " doesn't have a number value");
	}
	return num;
    }

    // [The keyword of this operand]
    private final Keyword kw;
    // [The string vaue of this operand.  May be null.]
    private final String str;
    // [The numeric value of this operand.  May be null.]
    private final Integer num;
}
